package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.query.TravelCommentQueryObject;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/comments")
public class CommentConreoller {
    @Autowired
    private ICommentService commentService;

    @GetMapping("/{travelId}")
    public PageInfo<Comment> List(TravelCommentQueryObject qo) {
        qo.setOrderBy("commentTime");
        return commentService.ListAllComments(qo);
    }

    @PostMapping
    public JsonResult save(Comment comment) {
        JsonResult jsonResult = new JsonResult();
        try {
            commentService.save(comment);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark("操作异常");
        }
        return jsonResult;
    }


}
